package controller;

import java.awt.Dimension;

import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import view.AppFrame;
import view.SVGPanel;

import model.SVG;

import apps.AppReg;

public class ZoomListener implements ChangeListener {

    @Override
    public void stateChanged(ChangeEvent arg0) {

	// Grab our variables
	SVG model = AppReg.getModel();
	AppFrame frame = AppReg.getFrame();
	SVGPanel panel = AppReg.getFrame().getSVGPanel();

	int zoom = frame.getToolBar().getZoom();// Get the zoom value
	float zoom_scale = (float) zoom / 100; // Put it into a scale where 1 =
					       // 100%

	frame.getToolBar().setZoomLabel(zoom + "%"); // Set label on zoom bar
	panel.setZoomScale(zoom_scale); // Pass to our panel the new scale

	// Resize the SVGPanel, scroll pane scroll bars will follow suit

	panel.setPreferredSize(new Dimension(
		(int) (model.getWidth() * zoom_scale),
		(int) (model.getHeight() * zoom_scale)));
	panel.setSize((int) (model.getWidth() * zoom_scale),
		(int) (model.getHeight() * zoom_scale));

	frame.repaint();

    }

}
